import { DefaultFooter, getMenuData, getPageTitle } from '@ant-design/pro-layout';
import { Helmet, HelmetProvider } from 'react-helmet-async';
import { Link, useIntl, connect } from 'umi';
import React,{useEffect, useState} from 'react';
import SelectLang from '@/components/SelectLang';
import {getPageQuery} from '@/utils/utils';
import logo from '../assets/logo.svg';
import styles from './UserLayout.less';


const UserLayout = props => {
  const { dispatch } = props;
  const [domain, setDomain] = useState(null);
  const [refresh, setRefresh] = useState(new Date().valueOf());
  useEffect(()=>{
    localStorage.setItem('x-yscloud-saas-domain','domain');
    // const params = getPageQuery();
    // if(params && params.domain){
    //   localStorage.setItem('x-yscloud-saas-domain',params.domain);
    //   dispatch({
    //     type:'login/domain',
    //     domain:params.domain,
    //     callback:(resp)=>{
    //       if(resp.result===1){
    //         setDomain(resp.returnValue)
    //       }else{
    //         setDomain(null);
    //         localStorage.removeItem('x-yscloud-saas-domain');
    //       }
    //     }
    //   });
    // }else{
    //   localStorage.removeItem('x-yscloud-saas-domain');
    // }
  },[refresh]);

  const links = [
    {
      key: 'lwkj',
      title: '联物科技',
      href: 'https://www.lianwukeji.com',
      blankTarget: true,
    },
    {
      key: 'yscloud',
      title: '怡生云',
      href: 'https://yishengyun.lianwukeji.com',
      blankTarget: true,
    },
  ];
  
  const copyright = '天津联物科技有限公司';

  const {
    route = {
      routes: [],
    },
  } = props;
  const { routes = [] } = route;
  const {
    children,
    location = {
      pathname: '',
    },
  } = props;
  const { formatMessage } = useIntl();
  const { breadcrumb } = getMenuData(routes);
  const title = getPageTitle({
    pathname: location.pathname,
    formatMessage,
    breadcrumb,
    ...props,
  });
  return (
    <HelmetProvider>
      <Helmet>
        <title>{'物联网管理平台'}</title>
        <meta name="description" content={'物联网管理平台'} />
      </Helmet>

      <div className={styles.container}>
        <div className={styles.lang}>
          <SelectLang />
        </div>
        <div className={styles.content}>
          <div className={styles.top}>
            <div className={styles.header}>
              <Link to="/">
                <img alt="logo" className={styles.logo} src={logo} />
                  <span className={styles.title}>{domain && domain.corporationname?domain.corporationname:'物联网管理平台'}</span>
              </Link>
            </div>
            {/* <div className={styles.desc}>Ant Design 是西湖区最具影响力的 Web 设计规范</div> */}
          </div>
          {children}
        </div>
        <DefaultFooter links={links} copyright={copyright} />
      </div>
    </HelmetProvider>
  );
};

export default connect(({ login,settings }) => ({ 
  settings:settings 
}))(UserLayout);
